﻿import { NgModule } from "@angular/core";
import {
  NavigationEnd,
  RouteConfigLoadEnd,
  RouteConfigLoadStart,
  Router,
  RouterModule,
} from "@angular/router";
import { AppComponent } from "./app.component";
import { AppRouteGuard } from "./shared/common/auth/auth-route-guard";
import { NotificationsComponent } from "./shared/layout/notifications/notifications.component";

@NgModule({
  imports: [
    RouterModule.forChild([
      {
        path: "app",
        component: AppComponent,
        canActivate: [AppRouteGuard],
        canActivateChild: [AppRouteGuard],
        children: [
          {
            path: "",
            children: [
              { path: "notifications", component: NotificationsComponent },
              { path: "", redirectTo: "/dashboard", pathMatch: "full" },
            ],
          },
          {
            path: "admin",
            loadChildren: "app/admin/admin.module#AdminModule", //Lazy load admin module
            data: { preload: true },
          },
          {
            path: "plan",
            loadChildren: "app/plan/plan.module#PlanModule", //Lazy load plan module
            data: { preload: true },
          },
          {
            path: "pipeline",
            loadChildren: "app/pipeline/pipeline.module#PipelineModule", //Lazy load pipeline module
            data: { preload: true },
          },
          {
            path: "domain",
            loadChildren: "app/domains/domain.module#DomainModule", //Lazy load domain module
            data: { preload: true },
          },
          {
            path: "material",
            loadChildren: "app/material/material.module#MaterialModule", //Lazy load material module
            data: { preload: true },
          },
          {
            path: "resource",
            loadChildren: "app/resource/resource.module#ResourceModule", //Lazy load resource module
            data: { preload: true },
          },
          {
            path: "datadisplay",
            loadChildren:
              "app/datadisplay/datadisplay.module#DatadisplayModule", //Lazy load resource module
            data: { preload: true },
          },
          {
            path: "workingtime",
            loadChildren:
              "app/workingtime/workingtime.module#WorkingtimeModule", //Lazy load resource module
            data: { preload: true },
          },
          
          {
            path: "**",
            redirectTo: "notifications",
          },
        ],
      },
    ]),
  ],
  exports: [RouterModule],
})
export class AppRoutingModule {
  constructor(private router: Router) {
    router.events.subscribe((event) => {
      if (event instanceof RouteConfigLoadStart) {
        abp.ui.setBusy();
      }

      if (event instanceof RouteConfigLoadEnd) {
        abp.ui.clearBusy();
      }

      if (event instanceof NavigationEnd) {
        $("meta[property=og\\:url]").attr("content", window.location.href);
        $("#m_aside_left").mOffcanvas().hide();
      }
    });
  }
}
